<template>
  <div id="app">
    sid:{{ sid }}
    uuid:{{ uuid }}

  </div>

</template>

<script>
import websocket from "@/plugins/websocket";

export default {
  name: "Push",
  data() {
    return {
      webSocket: null,
      uuid: '',
      sid: '',
      rid: '',
      reset: false,
      url: 'ws://ink.test/websocket',
      // url: 'ws://www.moyuu.cn/websocket',
    }
  },
  watch: {
    uuid: {
      handler() {
        this.uuid = this.$store.getters.getUUid;
      },
      immediate: true
    },
    sid: {
      handler() {
        this.sid = this.$store.getters.getSid;
      },
      immediate: true
    },

  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      var that = this;
      if (typeof (WebSocket) === "undefined") {
        this.$alert("您的浏览器不支持socket");
      } else {
        if (!that.$store.getters.getUUid || !that.$store.getters.getSid || !that.$store.getters.getToken) {
          that.$axios.post('identity/auth').then(res => {
            if (res.data.code == 1) {
              //TODO:cookie存储返回的数据并初始化websocket
              that.$store.commit('setIdentity', res.data.data);
              that.webSocket = websocket.init(this.url);
            }
          })
        } else {
          that.webSocket = websocket.init(this.url);
        }

      }
    }
  }
}
</script>

<style scoped>

</style>